$.extend({
	loadPreview:function(){
		var jsonData = $.getForm("form");
		var imgData = jsonData.multi[0];
		var imgUrl = null;
		if(imgData != null){
			if(imgData.fileFile != null && imgData.fileFile != undefined && 
					imgData.urlInfor != null && imgData.urlInfor != undefined){
				imgUrl = imgData.urlInfor + imgData.fileFile;
			}
		}
		console.log(imgData);
		var data = jsonData.obj[0];
		var oldHtml = $('body').html();
		var html = '<div class="container" id="header">';
		html += '<div class="row title"><div class="col-1 col-sm-1"><img src="static/ssjf/img/symbol/back_w.png"></div>';
		html += '<div class="col-10 col-sm-10">预览</div><div class="col-1 col-sm-1"></div></div></div>';
		html += '<div class="container" id="content"><div class="row"><div class="col-12 img_max">';
		if(imgUrl == null)html += '<img src="upload/file/empty-img.png">';
		else html += '<img src='+ imgUrl +'>';
		html += '</div></div>';
		html += '<div class="row"><div class="col-12 deadline">贷款截止时间：'+data.deadline+'</div></div></div>';
		html += '<div class="row new_row"><div class="col-12 product_title"><div class="row new_row"><div class="col-12">融资限额：'+ data.money +'万元</div></div>';
		html += '	<div class="row new_row"><div class="col-12">产品名称：'+data.title+'</div></div></div></div>';
		html += '<div class="row new_row content_text"><div class="col-12 color">办理条件</div><div class="row new_row content_detail"><div class="col-12">';
		html += '	<span>'+data.condition+'</span></div></div></div>';
		html += '<div class="row new_row content_text"><div class="col-12 color">办理流程</div>';
		html += '	<div class="row new_row content_detail"><div class="col-12"><span>'+data.procedure+'</span></div></div></div>';
		html += '<div class="row new_row content_text"><div class="col-12 color">产品简介</div>';
		html += '	<div class="row new_row content_detail"><div class="col-12"><span>'+data.intro+'</span></div></div></div>';
		html += '<div class="grey_line"></div>';
		html += '<div class="row new_row content_text"><div class="col-12 color">关于我们</div><div class="row new_row content_detail">';
		html += '	<div class="col-12"><span><span class="dot">·</span>公司规模：'+data.size+'</span>';
		html += '	<span><span class="dot">·</span>融资周期：'+data.period+'</span>';
		html += '	<span><span class="dot">·</span>联系部门：'+data.department+'</span>';
		html += '	<span><span class="dot">·</span>联系电话：<span class="number">'+data.number+'</span></span></div></div></div>';
		html += '<div class="row new_row" id="conn_btn"><div class="col-12">对接</div></div></div>';
		$('body').empty();
		$('body').css("background-image","inherit");
		$('body').append(html);
		$(".title").click(function(){
			$('body').empty();
			$('body').css("background-image","url(static/ssjf/img/bg/bg_blue.png)");
			$('body').append(oldHtml);
			$(".publish").click(function(){
				var jsonData = $.getForm("form");
				$.ajax({
					url:"ssjf/upload/sub",
					type:"POST",
					data:JSON.stringify(jsonData),
					dataType:"json",
					contentType: "application/json; charset=utf-8",
					success:function(result){
						if(result.res == 1){
							location.href = 'ssjf/index.html';
						}else{
							console.log("上传失败");
						}
					},
					error:function(error){
						console.log(error);
					}
				});
			});
			$(".preview").click(function(){
				$.loadPreview();
			});
		});
	}
});
function addTitle(title){
	form_html += "<!-- " + title + " -->";
	form_html += "<div class=\"row\">";
	form_html += "	<div class=\"col-1 margin-t-1d8r\"><span class=\"verline margin-l-d6r\"></span></div>";
	form_html += "	<div class=\"col-8 margin-t-1d8r\"><span class=\"color-999797 font-size-1d2r\">" + title + "</span></div>";
	form_html += "</div>";
}

function addInput(title,name,type){
	form_html += "<div class=\"row margin-t-1r\">";
	form_html += "	<div class=\"col-1 col-sm-2\"></div>";
	form_html += "	<div class=\"col-10 col-sm-8 flex\">";
	form_html += "		<span class=\"color-E66436 padding-r-0\">" + title + "：&nbsp;</span>";
	if(type == "textarea"){
		form_html += "		<textarea rows=\"4\" class=\"upload-input\" name=\"" + name + "\" value=\"\" placeholder=\"请输入" + title + "\" ></textarea>";
	}else form_html += "		<input type=\"" + type + "\" class=\"upload-input\" name=\"" + name + "\" value=\"\" placeholder=\"请输入" + title + "\" />";
	form_html += "	</div>";
	form_html += "</div>";
}
var form_html = "<!-- 产品上传 js生成 -->";
var old;
$(function () {
	old = $("#upload-body").html();
	addTitle("产品简介");
	addInput("产品名称","title","text");
	addInput("产品金额","money","text");
	addInput("融资周期","period","text");
	addInput("办理条件","condition","textarea");
	addInput("办理流程","procedure","textarea");
	addInput("办理简介","intro","textarea");
	addTitle("关于我们");
	addInput("公司规模","size","text");
	addInput("联系部门","department","text");
	addInput("联系电话","number","text");
	addInput("截止时间","deadline","text");
	addTitle("图片上传");
	form_html += old;
	$("#upload-body").html(form_html);

//    var file = $("#files-btn");
//    $(".add-btn").click(function() {
//        file.click();
//    });
//    file[0].addEventListener('change', function() {
//        var file = this.files[0];
//        var reader = new FileReader();
//        reader.readAsDataURL(file);
//        reader.onload = function(e) {
//            var newUrl = this.result;
//            var img_str = '<div class="preview-photo">';
//            img_str += '<img class="preview-photo-photo" width="40px" height="40px" src="' + newUrl + '" />';
//            img_str += '<img onclick="del(this)" class="del-btn remove-this" src="static/ssjf/img/del_btn.png" />';
//            img_str += '</div>';
//            $(".add-btn").parent().after(img_str);
//        };
//    });
	$(".publish").click(function(){
		var jsonData = $.getForm("form");
		$.ajax({
			url:"ssjf/upload/sub",
			type:"POST",
			data:JSON.stringify(jsonData),
			dataType:"json",
			contentType: "application/json; charset=utf-8",
			success:function(result){
				if(result.res == 1){
					location.href = 'ssjf/index.html';
				}else{
					console.log("上传失败");
				}
			},
			error:function(error){
				console.log(error);
			}
		});
	});
	$(".preview").click(function(){
		$.loadPreview();
	});
});

//function del(_this) {
//    var _this_img = $(_this);
//    _this_img.parent().remove();
//}

